package intro;

/**
 * 了解守护线程 以及守护线程的 finally 语句块
 * 
 * @author insight
 * @since 2021/8/23
 */
public class DaemonTest {
    /**
     * 随着守护线程的启动 main 线程执行完毕 JVM 退出
     * 所以没有执行 finally
     */
    public static void main(String[] args) {
        Thread t = new Thread(new DaemonRunner(), "DaemonRunner");
        t.setDaemon(true);
        t.start();
    }

    static class DaemonRunner implements Runnable {
        @Override
        public void run() {
            try {
                System.out.println("DaemonRunner Launched");
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            } finally {
                System.out.println("DaemonRunner Terminated");
            }
        }
    }
    
}